﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Student_Result
    {
      //  [Description("ID")]
            public long ID{get;set;}
      //  [Description("StudentID")]
            public long StudentID{get;set;}
      //  [Description("Subject_PointColumnID")]
            public long Subject_PointColumnID{get;set;}
        [Description("Điểm")]
            public int Value{get;set;}
      //  [Description("Xếp loại")]
            public long Rating{get;set;}
        public bool IsStudied { get; set; }
        [Description("Xếp loại")]
        public string RateExt { get; set; }
        [Description("Mã học viên")]
            public string StudentCodeExt { get; set; }
        [Description("Tên học viên")]
            public string StudentNameExt { get; set; }
        [Description("Lớp")]
            public string ClassNameExt { get; set; }
        [Description("Khóa")]
            public string CourseNameExt { get; set; }
        [Description("Ngành")]
            public string BranchNameExt { get; set; }
        [Description("GVCN")]
            public string TeacherNameExt { get; set; }
        [Description("Môn học")]
            public string SubjectNameExt { get; set; }
        [Description("Học kỳ")]
        public string SemeterExt { get; set; }
        [Description("Cột điểm")]
            public string PointColumnNameExt { get; set; }
        [Description("Hệ số")]
            public int FactorExt { get; set; }
      //  [Description("Tổng")]
            public float TotalExt { get; set; }
            public bool LockExt { get; set; }
    

         
        public Student_Result()
        {
            IsStudied = false;
        }
        
       static Student_Result DynamicCast<T>(object row_data, object row_header) where T : Student_Result
       {
           // row_data : DataRow
           // row_header : DataColumnCollection
           Student_Result ret = new Student_Result();
           DataRow dt = (DataRow)row_data;

           foreach (DataColumn column in (DataColumnCollection)row_header)
           {
               switch (column.ColumnName)
               {
                      case  "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "StudentID":
                        ret.StudentID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "Subject_PointColumnID":
                       ret.Subject_PointColumnID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "Value":
                        ret.Value = ConvertObject.ToInt(dt[column]);
                       break;
                      case  "Rating":

                        ret.Rating = ConvertObject.ToInt(dt[column]);
                        if (ret.Rating == 0)
                        {
                            ret.RateExt = "Chưa xếp loại";
                        }
                        if (ret.Rating == 1)
                        {
                            ret.RateExt = "Xuất sắc";
                        }
                        if (ret.Rating == 2)
                        {
                            ret.RateExt = "Giỏi";
                        }
                        if (ret.Rating == 3)
                        {
                            ret.RateExt = "Khá";
                        }
                        if (ret.Rating == 4)
                        {
                            ret.RateExt = "Trung bình";
                        }
                        if (ret.Rating == 5)
                        {
                            ret.RateExt = "Yếu";
                        }
                        if (ret.Rating == 6)
                        {
                            ret.RateExt = "Kém";
                        }
                       break;
                      case "StudentCode":
                       ret.StudentCodeExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "StudentName":
                       ret.StudentNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "ClassName":
                       ret.ClassNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "CourseName":
                       ret.CourseNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "BranchName":
                       ret.BranchNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "TeacherName":
                       ret.TeacherNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "SubjectName":
                       ret.SubjectNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "PointColumnName":
                       ret.PointColumnNameExt = ConvertObject.ToString(dt[column]);
                       break;
                      case "Factor":
                       ret.FactorExt = ConvertObject.ToInt(dt[column]);
                       break;
                      case "Total":
                       ret.TotalExt = ConvertObject.ToFloat(dt[column]);
                       break;
                   case "IsStudied":
                       ret.IsStudied = ConvertObject.ToBool(dt[column]);
                       break;
                   case "Lock":
                       ret.LockExt = ConvertObject.ToBool(dt[column]);
                       break;
                   case "SemeterName":
                       {
                           ret.SemeterExt = ConvertObject.ToString(dt[column]);
                           if (ret.SemeterExt == "0")
                               ret.SemeterExt = "Học kỳ I";
                           else
                           { ret.SemeterExt = "Học kỳ II"; }

                       }
                       break;
                   default:
                       break;
               }
           }

           return ret;
       }
        
    }
}
